﻿function ErrhandledbClick(o)
{   
    try
    {
	    if (!o)
	    {
		    o = event.srcElement;
	    }

	    if (!o.selected && o.parentElement.parentElement.id!="title")
	    {
		    Errfocus();
		    ErrhandleSelectRow();
	    }
	}
	catch (e)
	{
	}
	finally
	{
	}
}

function ErrhandleSelectRow(o)
{   
    try
    {
		if (!o)
		{
			o = event.srcElement.parentElement.parentElement;
		}
  		if (event && event.shiftKey && GRID_SUPPORT_MULTISELECT && _iLastPickedIndex != -1)
		{
			ErrunselectRows(o);
		}
		else
		{	
			ErrselectRow(o);
			
			var LocalControler = parent.document.getElementById(o.cells[2].innerText);
			switch(LocalControler.tagName){
			case "INPUT":
					LocalControler.select();
			case "SELECT":
					LocalControler.focus();
			case "TEXTAREA":
			        LocalControler.select();
			}
			 
			if (event && !event.ctrlKey || !GRID_SUPPORT_MULTISELECT)
			{
				ErrunselectRows(o);
			}
			else if(event && event.ctrlKey)
			{
				ErrunselectRows(o);
			}
			_iLastPickedIndex = o.rowIndex;
		}
	//window.parent.gridBar.RefreshStatus();
	}
	catch (e)
	{
		ShowError("滑鼠未點選到錯誤項目!!");
	}
}

/*
	focus錯誤位置並且更換底色
*/
function Errfocus()
{   
    try
    {
	    for(var i=1;i<ErrMsgTable.rows.length;i++)
	    {
			//增加處理textarea 錯誤
	        if( parent.document.getElementById(ErrMsgTable.rows[i].cells[2].innerText).tagName=="INPUT" || parent.document.getElementById(ErrMsgTable.rows[i].cells[2].innerText).tagName=="TEXTAREA" )
			{
				//增加判斷如果被隱藏錯誤訊息點選後不被FOCUS住add by samantha 2005/5/11
				if(ErrMsgTable.rows[i].style.display!="none") 
				{
				    parent.document.getElementById(ErrMsgTable.rows[i].cells[2].innerText).style.background = "#FFDFDC";
				}
			}
	    }
	}
	catch (e)
	{
		ShowError( "函式 Errfocus() : " + e.message);
	}
}


//unselecedros
function ErrunselectRows(oSkip)
{   
    try
    {
	    var o = oSkip.parentElement.parentElement;
	    for (var i=0; i < o.rows.length; i++)
	    {
		    var oTr = o.rows[i];
		    if (oTr !== oSkip)
		    {
			    ErrunselectRow(oTr);
			    //collapseRow(oTr);
		    }
	    }
	}
	catch (e)
	{
	}
	finally
	{
	}
}
function ErrunselectRow(o)
{   
    try
    {
	    if (o.selected)
	    {
		    window.parent._iNumSelected--;
		    o.selected = false;
		    o.style.paddingTop = "1px";
		    ErrapplyStyle(o, "detail");
	    }
	}
	catch (e)
	{
	}
	finally
	{
	}
}
//selectRow
function ErrselectRow(o)
{   
    try
    {
	    if (!o.selected && o.firstChild.className != "gridPreview")
	    {
		    window.parent._iNumSelected++;
		    o.selected = true;
		    o.style.paddingTop = "0px";
		    ErrapplyStyle(o, "ErrOnSeleced");
	    }
	}
	catch (e)
	{
	}
	finally
	{
	}
}
function ErrapplyStyle(o, sClass)
{
	var i = 0;
	try
	{
	var ii = o.cells.length;

	while (i < ii)
	{
		o.cells[i].className = sClass;
		i++;
	}
	}
	catch (e)
	{
	}
	finally
	{
	}
}